package cn.stylefeng.guns.modular.yingbao.controller;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.yingbao.entity.UserMoney;
import cn.stylefeng.guns.modular.yingbao.model.params.UserMoneyParam;
import cn.stylefeng.guns.modular.yingbao.service.UserMoneyService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import oracle.jdbc.proxy.annotation.Post;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.annotation.Schedules;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


/**
 * 用户金额控制器
 *
 * @author zs
 * @Date 2019-12-10 15:56:19
 */
@CrossOrigin
@Controller
@RequestMapping("/userMoney")
@Api(tags = "资金模块")
public class UserMoneyController extends BaseController {

    private String PREFIX = "/userMoney";

    @Autowired
    private UserMoneyService userMoneyService;

    /**
     * 跳转到主页面
     *
     * @author zs
     * @Date 2019-12-10
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/userMoney.html";
    }

    /**
     * 新增页面
     *
     * @author zs
     * @Date 2019-12-10
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/userMoney_add.html";
    }

    /**
     * 编辑页面
     *
     * @author zs
     * @Date 2019-12-10
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/userMoney_edit.html";
    }

    /**
     * 新增接口
     *
     * @author zs
     * @Date 2019-12-10
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(UserMoneyParam userMoneyParam) {
        this.userMoneyService.add(userMoneyParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author zs
     * @Date 2019-12-10
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(UserMoneyParam userMoneyParam) {
        this.userMoneyService.update(userMoneyParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author zs
     * @Date 2019-12-10
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(UserMoneyParam userMoneyParam) {
        this.userMoneyService.delete(userMoneyParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author zs
     * @Date 2019-12-10
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(UserMoneyParam userMoneyParam) {
        UserMoney detail = this.userMoneyService.getById(userMoneyParam.getId());
        return ResponseData.success(detail);
    }
    /**
     * 查看详情接口
     *
     * @author zs
     * @Date 2019-12-10
     */
    @CrossOrigin
    @RequestMapping(value = "/appDetail",method = RequestMethod.POST )
    @ResponseBody
    @ApiOperation("查看相关资金")
    public ResponseData detail(Long userid) {
        if (userid == null){
            return ResponseData.error("参数错误");
        }
        UserMoney detail = this.userMoneyService.getOne(new QueryWrapper<UserMoney>().eq("userid",userid));
        return detail==null?ResponseData.error("暂无数据"):ResponseData.success(detail);
    }

    /**
     * 查看详情接口
     *
     * @author zs
     * @Date 2019-12-10
     */
    @CrossOrigin
    @RequestMapping(value = "/appOut",method = RequestMethod.POST )
    @ResponseBody
    @ApiOperation("转出冻结资金")
    public ResponseData appOut(Long userid) {

        return userMoneyService.appOut(userid);
    }
    /**
     * 查询列表
     *
     * @author zs
     * @Date 2019-12-10
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(UserMoneyParam userMoneyParam) {
        return this.userMoneyService.findPageBySpec(userMoneyParam);
    }


}


